import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.jws.WebService;

import connection.ConnectionDB;

@WebService()
public class Autenticacao {
	public void Autenticacao() {
	}

	public ConnectionDB con = new ConnectionDB();

	public boolean validarSenha(String user, String pass) {

		Connection cn = null;
		Statement st = null;
		ResultSet rs = null;

		String usr = null;
		String senha = null;
		boolean retorno = false;

		try {
			cn = con.connect();

			String sql = "select email as login, senha as senha from cliente where email = '"
					+ user + "' and senha = '" + pass + "'";

			// Buscar Email e Senha
			st = cn.createStatement();
			rs = st.executeQuery(sql);

			while (rs.next()) {
				usr = rs.getString("login");
				senha = rs.getString("senha");
			}

			System.out.println(sql);

			sql = "commit";
			st = cn.createStatement();
			rs = st.executeQuery(sql);

			System.out.println("user = " + user);
			System.out.println("usr = " + usr);
			System.out.println("pass = " + pass);
			System.out.println("senha = " + senha);

			if (user.equals(usr) && pass.equals(senha)) {
				retorno = true;
			}

			cn.close();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return retorno;
	}
}